<?php

include_once 'inc/fire/FirePHP.class.php';
session_start();
ob_start();

function __autoload($class_name) {
    //$firephp = FirePHP::getInstance(true);
    //$firephp->log($class_name, "class_name");
    $fullclasspath = "";
    $suffix = "";
    if (!file_exists('inc/' . $fullclasspath . $class_name . ".php")) {
        if (!file_exists('inc/' . $fullclasspath . $class_name . ".class.php")) {
            if (file_exists('inc/utility/' . $class_name . ".class.php")) {
                $fullclasspath = "utility/";
                $suffix = ".class";
            }
        } else {
            $suffix = ".class";
        }
    }
//echo 'inc/' . $fullclasspath . $class_name . $suffix . '.php<br />';
    require_once 'inc/' . $fullclasspath . $class_name . $suffix . '.php';
}
$action = (!isset($_POST['function'])) ? "showpage" : $_POST['function'];


$log = new URLRouter($action);

//$u = new URLParser($action);
/*$func = $u->getParsedURL();
///$firephp->log($func, "parsed");
switch ($func['func']) {
    case "startsession": {
            echo $log->returnToken();
            break;
        }
    case "login": {
            echo $log->logUser();
            break;
        }
    case "logout": {
            echo $log->unLogUser();
            break;
        }
    case "amnistia": {
            $log = new Template(12);
            $log->setText();
            echo $log->outputHTML();
            break;
        }
    case "intructivo": {
            $log = new Template(14);
            $log->setText();
            echo $log->outputHTML();
            break;
        }
    case "showpage": {
            $log->show_page();
            break;
        }
    default: {
            //$firephp->log($func, "parsed2");
            $respuesta["error"] = true;
            $respuesta["mensaje"] = array('span' => '"' . $action . '" Funcion No encontrada');
            $respuesta['div'] = 'login';
            echo json_encode($respuesta);
            break;
        }
//}
//} else {
//$log->show_page();
//}
        $firephp->log(serialize($log));
        unset($log);*/
//print_r( date('d:m:y h:i:s'));
    /*
      //$conn=new connection();
      //$conn->simpleQuery('alania_contenidos',array("id"=>1,"nom1"=>"nom2","nombre"=>array("date"=>array("day"=>1,"month"=>2,"year"=>1999),"time"=>array("hour"=>1,"minute"=>0,"second"=>0))));
      $x = new AlaniaUsuarioModel();


      $x->findById($db->db, 1);
      print_r($x->toEzcPersistentObjectDefinition()); */
//include_once 'inc/AlaniaUsuarioModel.class.php';
//$db=new PDO('mysql:dbname=mydb;host=localhost', 'root', '');
    /* $db = new connection();
      // query all members with dexterity=12 and reasoning=4 (query by example currently only available for PDO!)
      $example = new AlaniaUsuarioModel();

      $example->setPassword(md5(4))->setIdentificacion('56');
      if(count(AlaniaUsuarioModel::findByExample($db->db, $example))){
      foreach (AlaniaUsuarioModel::findByExample($db->db, $example) as $member) {
      //echo $member->getIdentificacion() . ':' . $member->getNombre() . "\n";
      echo $member->toDOM()->saveHTML();
      }
      }else{
      echo "Usuario No Existe";
      }
     */
//$example = new AlaniaUsuarioModel();
//$example->setIdUsuario(6)->setNombre('principal1')->setIdentificacion("60")->setApellido("2")->setPassword(md5("4"));
//$example->insertIntoDatabase($db->db);
// get single member for PK
    /* $member = AlaniaUsuarioModel::findById($db->db, 4);
      var_dump($member->toArray());
      echo $member->getNombre(); */
    /* $member->setApellido('prueba2');
      //$member->setMagic(100);
      $member->updateToDatabase($db);


      // a bit more flexible filters (currently only available for PDO!)
      //include_once 'inc/utility/DFC.class.php';
      $filter = array(
      new DFC(AlaniaUsuarioModel::FIELD_NOMBRE, 'a', DFC::BEGINS_WITH), // value of field name begins with s
      new DFC(AlaniaUsuarioModel::FIELD_ID_USUARIO, 1, DFC::GREATER) // value of field physique is greater 10
      );
      foreach (AlaniaUsuarioModel::findByFilter($db, $filter) as $member) {
      echo $member->getId() . ':' . $member->getName() . ':' . $member->getPhysique() . "\n";
      var_dump($member->toArray());
      } */
//}
//$firephp->log(memory_get_usage());
?>